import tesserocr
from PIL import Image

# image = Image.open("./code.jpg")
image = Image.open("./code2.png")
# lang = tesserocr.get_languages()
# print(lang)
# image = image.convert("L")
# # image.show()
# image = image.convert("1")
# # image.show()
# res = tesserocr.image_to_text(image)
# print(res)

#
# res_data = tesserocr.file_to_text("./code.jpg")  # 效果不如上面
# print(res_data)

# 二值化图像传入图像和阈值
image = image.convert('L')
threshold = 80
table = []
for i in range(256):
    if i < threshold:
        table.append(0)
    else:
        table.append(1)
image.point(table, '1')
image.show()
print(tesserocr.image_to_text(image))


